<?php
/**
 * The user management portal
 * 
 * This page allows the administrator to modify user accounts on the system
 * @author James Ravenscroft
 * @license LGPL
 * @package Edify
 */

include('login.php');
$prefix = $database_prefix;
//Start database connection
$dbh = new dbal("$database_protocol://$database_username:$database_password@$database_host/$database_database");
$dbh->setCacheDir("../cache"); 

//begin templating
$smarty = new Smarty;
$smarty->compile_dir = "../templates_c";
$smarty->template_dir = "../templates";
$smarty->cache_dir = "../cache";
$dbh->compile("SELECT * FROM {$prefix}_registry WHERE cluster LIKE :group ORDER BY cluster");
$r = $dbh->query(array('group' => '%.admin.%.indexLink'));

//build admin menu
while($row = $r->getNext())
{
	if($row['key'] == 'admin_title')
		$array[$row['cluster']]['text'] = $row['value'];
	elseif($row['key'] == 'admin_interface')
		$array[$row['cluster']]['url'] = $row['value'];
}

foreach($array as $key=>$el)
{
	$link[] = $el;
}

$smarty->assign('link', $link);
$smarty->assign('pageTitle',"Edify Admin Interface");


$clinks[0]['url'] = "?";
$clinks[0]['text'] = "User Index";
$clinks[1]['url'] = "?do=new";
$clinks[1]['text'] = "New User";
	
$smarty->assign('contextLinks', $clinks);

//do page stuff
switch($_GET['do'])
{
	case 'new':
		include("users/new.php");
		break;
	
	case 'edit':
		break;
		
	case 'delete':
		break;
		
	default:
		$r = $dbh->query("SELECT * FROM {$prefix}_users");
		while($row = $r->getNext())
			$users[] = $row;
		$smarty->assign('users', $users);
		$smarty->assign('formTitle', "User Management Index");
		$pageContent = $smarty->fetch('admin/users/index.tpl');
		break;
}

$smarty->assign('pageContent', $pageContent);
$smarty->display('admin/index.tpl');
?>